<?php
// 用户模型
class UserModel extends CommonModel {
	public $_validate	=	array(
        array('user_name','/^[a-z]\w{3,}$/i','帐号格式错误'),
        array('password','require','密码必须'),
        array('nick_name','require','昵称必须'),
        array('repassword','require','确认密码必须'),
        array('password','6,100','密码长度最少6位',1,'length'), // 验证密码长度
        array('repassword','password','确认密码不一致',self::EXISTS_VALIDATE,'confirm'),
        array('user_name','','帐号已经存在',self::EXISTS_VALIDATE,'unique',self::MODEL_INSERT),
        );

    public $_auto		=	array(
        array('password','pwdMd5',self::MODEL_BOTH,'callback'),
        array('create_time','time',self::MODEL_INSERT,'function'),
        array('update_time','time',self::MODEL_UPDATE,'function'),
        );

    protected function pwdHash() {
        if(isset($_POST['password'])) {
            return pwdHash($_POST['password']);
        }else{
            return false;
        }
    }

    protected function pwdMd5() {
        if(isset($_POST['password'])) {
            return md5($_POST['password']);
        }else{
            return false;
        }
    }
}
?>